package com.atguigu.tingshu.user.factory.impl;

import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.user.factory.PurchaseStrategyFactory;
import com.atguigu.tingshu.user.strategy.PurchaseStrategy;
import com.atguigu.tingshu.user.strategy.impl.AlbumPurchaseStrategy;
import com.atguigu.tingshu.user.strategy.impl.TrackPurchaseStrategy;
import com.atguigu.tingshu.user.strategy.impl.VipPurchaseStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author atguigu-mqx
 * @ClassName PurchaseStrategyFactoryImpl
 * @description: TODO
 * @date 2024年04月29日
 * @version: 1.0
 */
@Service
public class PurchaseStrategyFactoryImpl implements PurchaseStrategyFactory {

    @Autowired
    private AlbumPurchaseStrategy albumPurchaseStrategy;

    @Autowired
    private TrackPurchaseStrategy trackPurchaseStrategy;

    @Autowired
    private VipPurchaseStrategy vipPurchaseStrategy;

    @Autowired
    Map<String,PurchaseStrategy> map = new HashMap<>();

    //  初始化数据放入map 集合。
    //    @PostConstruct
    //    public void init(){
    //        map.put(SystemConstant.ORDER_ITEM_TYPE_ALBUM,albumPurchaseStrategy);
    //        map.put(SystemConstant.ORDER_ITEM_TYPE_TRACK,trackPurchaseStrategy);
    //        map.put(SystemConstant.ORDER_ITEM_TYPE_VIP,vipPurchaseStrategy);
    //    }
    /**
     *
     * @param itemType
     * @return
     */
    @Override
    public PurchaseStrategy getStrategy(String itemType) {
        //        if (itemType.equals("1001")){
        //            return albumPurchaseStrategy;
        //        } else if (itemType.equals("1002")){
        //            return trackPurchaseStrategy;
        //        } else {
        //            return vipPurchaseStrategy;
        //        }
        return map.get(itemType);
    }
}
